-- resonance
-- created by panyl
-- 共鸣属性（同类越多属性越多）

return {
    apply = function(prop, baseValue)
        return baseValue;
    end,

    -- 每回合触发
    trigger = function(who, prop, base)
        if who.type ~= OBJECT_TYPE_MONSTER then
            return;
        end

        local count = 0;
        local layer = DungeonM.currentLayer();
        for pos = 1, GRID_SIZE do
            local grid = DungeonM.getGridByPos(pos);
            local monster = grid.monster;

            -- 如果还未翻开，或者不是怪物，或者不是同类，或者已经死亡
            if  grid:isOpened() and grid:isMonster() and
                monster and monster:getName() == who:getName() and
                not monster:isDead() and monster ~= who then
                count = count + 1;
            end
        end

        local baseAttrib = base or who.dbase:query(prop[2], 0);
        local value = math.max(FormulaM.invoke("CALC_BIG_DIVISION", count * prop[3], baseAttrib, 1000), count);
        return baseAttrib + value;
    end,

    record = function(target, prop, path)
        return false;
    end
};
